// contntesManager
(function ($, undefined) {

    // define the name of the UI component
    var ui_name = "contentsManager"

    // initialize object
    var cm = $.contentsManager = {

        // default values
        defaults: {

    },

    setDefaults: function (defaultOptions) {
        this.defaults = $.extend({}, this.defaults, defaultOptions);
    }
};

$.fn.contentsManager = function (options) {

    // method calling
    if (typeof options == 'string') {
        var args = Array.prototype.slice.call(arguments, 1),
			    res;
        this.each(function () {
            var data = $.data(this, ui_name);
            if (data) {
                var meth = data[options];
                if (meth) {
                    var r = meth.apply(this, args);
                    if (res === undefined) {
                        res = r;
                    }
                }
            }
        });
        if (res !== undefined) {
            return res;
        }
        return this;
    }

    // initialize options
    options = $.extend({}, cm.defaults, options);

    this.each(function () {
        var _self = this;
        showContentBox();


        // initialize callback
        for (var key in options) {
            var value = options[key];
            if (typeof value == 'function') {
                // bind callbacks
                $(_self).bind(key, value);
            }

        }

        /* Private Methods
        -----------------------------------------------------------------------------*/
        function showContentBox() {
            if (!options.width) {
                var width = "400px";
            } else {
                var width = options.width;
            }


            if (!options.height) {
                var height = "300px";
            } else {
                var height = options.height;
            }

            var newContent = $('<div class="popup_block"/>')
                                  .append('<a href="#" class="close"><img src="../../Content/images/close_pop.png" style="border:0px;" class="btn_close" title="Close Window" alt="Close" /></a>')
                                  .append($(_self).clone(true).show())
                                  .css({ 'width': width, 'height': height })
                                  .appendTo('body');

            var left = ($(window).width() - $(newContent).width()) / 2;
            var top = ($(window).height() - $(newContent).height()) / 2;

            $(newContent).css({
                'left': left + 'px',
                'top': top + 'px'
            });


            $('body')
                 .append('<div id="fade"></div>');
            $('#fade').css({ 'filter': 'alpha(opacity=80)' }).fadeIn();

            $(newContent)
                 .fadeIn();


            $('a.close, #fade').live('click', function () {
                $('#fade , .popup_block').fadeOut(function () {
                    $(newContent).remove();
                });
                return false;
            });
        };




        /* Callback Triggers
        -----------------------------------------------------------------------------*/




        /* Public Methods
        -----------------------------------------------------------------------------*/

        var publicMethods = {
            option: function (name, value) {
                if (value === undefined) {
                    return options[name];
                }
                options[name] = value;
            }



            // @other public methods
        };

        $.data(this, ui_name, publicMethods);


        // @private methods


        // define callback triggers

        //function select() {
        //    var val = 12345;
        //    $(_self).trigger('select', val);
        //}

    });

    return this;
};

// @static methods

})(jQuery);
//var EzContntesManager = {};

//EzContntesManager = {


//    showContentBox: function (selector) {


//        var newContent = $('<div class="popup_block"/>')
//                          .append('<a href="#" class="close"><img src="/Content/images/close_pop.png" style="border:0px;" class="btn_close" title="Close Window" alt="Close" /></a>')
//                          .append($(selector).clone().show())
//                          .css({ 'width': '400px', 'height': '300px' })
//                          .appendTo('body');

//        var left = ($(window).width() - $(newContent).width()) / 2;
//        var top = ($(window).height() - $(newContent).height()) / 2;

//        $(newContent).css({
//            'left': left + 'px',
//            'top': top + 'px'
//        });


//        $('body')
//         .append('<div id="fade"></div>');
//        $('#fade').css({ 'filter': 'alpha(opacity=80)' }).fadeIn();

//        $(newContent)
//         .fadeIn();


//        $('a.close, #fade').live('click', function () {
//            $('#fade , .popup_block').fadeOut(function () {
//                $(newContent).remove();
//            });
//            return false;
//        });
//    }
//}

